<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>生意帮</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
    <link rel="stylesheet" type="text/css" href="../../css/swiper.min.css">
    <link rel="stylesheet" type="text/css" href="../../css/aui-slide.css" />
    <style>
        html,
        body {
            background-color: transparent;
        }
        .boxB {
          position: relative;;
          width: 100%;
          height: 100vh;
        }
        .mask {
          position: absolute;
          width: 100%;
          height: 100%;
          background-color: rgba(0,0,0,0.3);
        }
        .box {
            background-color: #fff;
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
        }

        .aui-content {
        }

        .head_right .aui-pull-right {
            border: 1px solid #999;
            border-radius: 50%;
            height: 1rem;
            width: 1rem;
            text-align: center;
            line-height: 1rem;
        }

        .aui-iconfont {
            font-size: 0.6rem;
            vertical-align: top;
        }

        .head_right {
            position: relative;
        }


        .clearfix:after {
            content: '';
            display: block;
            clear: both;
        }
        #app .aui-list-header {
          background: #fff;
        }
        .aui-list-header i {
          font-style: normal;
          font-size: 1rem;
        }
        .Submit {
          background: url(../../image/header_bg.png) no-repeat center !important;
          font-size: 0.8rem;
          color: #fff;
          text-align: center;
          padding: 0.5rem 0
        }
        .aui-radio:checked{
          background-color: #f23030;
          border: solid 1px #f23030;
        }
    </style>
</head>

<body>
  <div id="app">
    <div class="boxB">
      <div class="mask" onclick="openF()"></div>
        <div class="box">
          <div class="aui-content">
                  <ul class="aui-list aui-media-list">
                      <li class="aui-list-header">
                          取消原因   <i onclick="openF()">×</i>
                      </li>
                      <li class="aui-list-item">
                           <label class="aui-list-item-inner">
                               <div class="aui-list-item-input">
                                 <div class="order_things" v-for="(item, index) in reason_list" :key="index">
                                    <div :id="reason_id">{{item.name}}</div>
                                    <input class="aui-radio" type="radio" v-model="reason_id" :value="item.reason_id">
                                 </div>
                               </div>
                           </label>
                       </li>
                  </ul>
              </div>
            <div class="Submit" @click="submit(reason_id)">
                确认
            </div>
        </div>
    </div>
  </div>

</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/utils.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/aui-tab.js"></script>
<script type="text/javascript" src="../../script/aui-scroll.js"></script>
<script type="text/javascript" src="../../script/aui-pull-refresh.js"></script>
<script type="text/javascript" src="../../script/swiper.min.js"></script>
<script type="text/javascript" src="../../script/aui-slide.js"></script>
<script type="text/javascript" src="../../script/aui-lazyload.js"></script>
<script type="text/javascript">
    function openF() {
        api.closeFrame();
    }

    apiready = function() {
      var app = new Vue({
        el: '#app',
        data: {
        reason_id: 0,
        reason_list: [],
        },
        created: function() {
        //  alert(api.pageParam.type)
          var $_this = this
          api.ajax({
              url: window.Url.Freeorder_orderReasonList,
              method: 'post',
              data: {
                  values: {
                      token: $api.getStorage('token'),
                      type: api.pageParam.type,
                  }
              }
          }, function(ret, err) {
              if (ret) {
              console.log(api.pageParam.type)
                console.log(JSON.stringify(ret))
                if (ret.re == 1) {
                  $_this.reason_list = ret.data.list
                } else {
                  $_this.reason_list = []
                }

              } else {
                  api.alert({msg: JSON.stringify(err)});
              }
          })

        },
        methods: {
          submit: function () {
            var $this = this
            console.log(api.pageParam.type)
            if(api.pageParam.type == 2) {
              api.sendEvent({
                  name: 'sqtk',
                  extra: {
                    id: $this.reason_id,
                    reason: $('#' + $this.reason_id).text(),
                  }
              })
              api.closeFrame()
            } else if (api.pageParam.type == 1) {
              api.ajax({
                  url: window.Url.Freeorder_cancelOrder,
                  method: 'post',
                  data: {
                      values: {
                          token: $api.getStorage('token'),
                          orderId:  api.pageParam.o_id,
                          reason_id: $this.reason_id,
                      }
                  }
              }, function(ret, err) {
                  if (ret) {
                    api.toast({ msg: ret.info,duration: 2000,location:'middle' });
                    setTimeout(function() {
                      api.execScript({
                          name: 'orderAll',
                          frameName: '1',
                          script: 'window.location.reload();'
                      })
                      api.execScript({
                          name: 'orderAll',
                          script: 'window.location.reload();'
                      })
                      api.closeFrame()
                    },2000)
                  } else {
                      api.alert({msg: JSON.stringify(err)});
                  }
              })
            }

          }
        },
        mounted: function () {
        }
      })
    }
</script>

</html>
